<template>
  <div class="role-container">
    <el-card class="role-card">
      <template #header>
        <div class="card-header">
          <span>角色管理</span>
          <el-button type="primary" @click="handleAddRole">添加角色</el-button>
        </div>
      </template>
      
      <el-table :data="roles" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="角色名称" />
        <el-table-column prop="code" label="角色编码" />
        <el-table-column prop="description" label="描述" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button 
              size="small" 
              type="danger" 
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'

const roles = ref([
  {
    id: 1,
    name: '超级管理员',
    code: 'SUPER_ADMIN',
    description: '系统超级管理员',
    createTime: '2024-01-01'
  },
  {
    id: 2,
    name: '普通用户',
    code: 'USER',
    description: '普通用户',
    createTime: '2024-01-01'
  }
])

const handleAddRole = () => {
  ElMessage.success('添加角色功能待实现')
}

const handleEdit = (role) => {
  ElMessage.success(`编辑角色 ${role.name} 功能待实现`)
}

const handleDelete = (role) => {
  ElMessageBox.confirm(`确定要删除角色 ${role.name} 吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success(`角色 ${role.name} 已删除`)
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}
</script>

<style scoped lang="scss">
.role-container {
  padding: 20px;
}

.role-card {
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style> 